package com.eascs.admin.o2o.financial.controller;

import java.text.DecimalFormat;
import java.text.Format;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.o2o.badloan.entity.O2oBadLoanPageVo;
import com.eascs.admin.o2o.badloan.service.O2oBadLoanService;
import com.eascs.admin.o2o.financial.service.O2oFinancialService;
import com.eascs.app.dao.PageResult;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.PaginationRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.workflow.common.service.sys.SysOrgService;

@RestController
@RequestMapping("/rfinancial")
public class O2oFinancialRestController extends BaseRestController {
		
	@Autowired
	O2oFinancialService financialService;
	@Reference
	SysOrgService sysOrgService;
	@Autowired
	private O2oBadLoanService badLoanService;

	/**
	 * @Description:
	 *               <p>
	 *               回款记录
	 *               </p>
	 * @author LMX
	 * @date 2018年1月3日 下午8:45:55
	 */
	@RequestMapping("/badloan_list")
	public PaginationRestResult findResult(O2oBadLoanPageVo vo) {
		vo.setPageSize(10);
		String findurl = "/rfinancial/badloan_list";
		String billCode = vo.getBillCode() == null ? "" : vo.getBillCode();
		findurl = UrlUtil.appendUrl(findurl, "billCode", billCode);
		findurl = findurl + "&pageIndex=";
		PageResult<Object[]> pageResult = badLoanService.findByPageRecord(vo);
		String titles[] = { "贷款单号", "终端贷单号", "省份", "借款人姓名", "经办平台", "贷款类型", "本次回款金额", "本次发起时间", "本次实际还款时间", "清收人", "流程状态" };
		SelectDataOption[] selectDataOptions = { null, null, new SelectDataOption("O2OPROVINCE"), null, null, new SelectDataOption("BAD_LOAN_TYPE"), null, null, null, null, new SelectDataOption("PAY_STATUS") };
		Button findBtn = ButtonHelper.createAjaxButton("", "/rbadloan/findRecordView?id=");
		Button[] detailButtons = new Button[] { findBtn };
		PaginationInfo o2oPagingInfo = new PaginationInfo(pageResult, titles, findurl);
		o2oPagingInfo.setBuildPagingNavigation(true);
		o2oPagingInfo.setFirstRenderColumnIndex(1);
		o2oPagingInfo.setTitleButtons(detailButtons);
		o2oPagingInfo.setSelectDataOptions(selectDataOptions);
		o2oPagingInfo.setFormats(new Format[] { null, null, null, null, null, null, new DecimalFormat(",##0.00"), null });
		o2oPagingInfo.setRendTo("#result_list");
		ViewContext.put("vo", vo);
		return PaginationRestResult.buildPaginationRestResult(o2oPagingInfo);
	}

}
